package com.ljsw.dialog;

import com.ljsw.activity.R;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

/**
 * 指纹验证之后 周转箱交接提示Dialog
 * 作者: 石锚
 * 版本: 1.0
 * 日期: 2015-10-14
 */
public class ZzxDialog {
	
	public ZzxDialog(Context context) {
		super();
		this.context = context;
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();//获取屏幕分辨率
	}
	
	private Context context;
	private Dialog dialog;
	private Display display;
	private TextView zzx_title;//标题
	private TextView msg;//内容
	private TextView queding,quxiao;//确定|取消
	private LinearLayout dialog_zzx;
	
	public ZzxDialog builder(){
		// 获取Dialog布局
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_zhouzhuanxiang, null);
		dialog_zzx = (LinearLayout) view.findViewById(R.id.dialog_zzx);
		zzx_title = (TextView) view.findViewById(R.id.zzx_title);
		queding = (TextView) view.findViewById(R.id.qd_zzx);
		quxiao = (TextView) view.findViewById(R.id.qx_zzx);
		msg = (TextView) view.findViewById(R.id.zzx_tishi);
		//添加Dialog样式
		dialog = new Dialog(context, R.style.ZzxDialog);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域不关闭Dialog	
		// 调整dialog背景大小
		dialog_zzx.setLayoutParams(new FrameLayout.LayoutParams((int) (display.getWidth() * 0.85), LayoutParams.WRAP_CONTENT));
		return this;
	}
	
	/**
	 * 设置标题
	 * @param title
	 * @return
	 */
	public ZzxDialog setTitle(String title){
		zzx_title.setText(title);
		return this;
	}
	/**
	 * 隐藏提示信息
	 * @return
	 */
	public ZzxDialog setGone(){
		msg.setVisibility(View.GONE);
		return this;
	}
	
	/**
	 * 确定事件
	 * @param text
	 * @param listener
	 * @return
	 */
	public ZzxDialog setPositiveButton(String text,
			final OnClickListener listener) {
		
		queding.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				listener.onClick(v);
				dialog.dismiss();
			}
		});
		return this;
	}
	/**
	 * 取消事件
	 * @param text
	 * @param listener
	 * @return
	 */
	public ZzxDialog setNegativeButton(String text,
			final OnClickListener listener) {
		quxiao.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				listener.onClick(v);
				dialog.dismiss();
			}
		});
		return this;
	}
	public void show() {
		dialog.show();
	}
}
